package ltd.jdsoft.cute.channel.util;

import javax.servlet.http.HttpServletRequest;

import org.springframework.util.StringUtils;

import ltd.jdsoft.cute.channel.exception.ChannelExceptionEnum;
import ltd.jdsoft.cute.spring.web.exception.BizException;

/**
 * 公共参数定义、校验
 * 
 * @author zhengzhq
 *
 */
public class CommonParams {

  // 合作方标识
  public static final String COOPERATOR = "cooperator";
  // 流水号
  public static final String REQ_MSGID = "reqMsgId";
  // 签名
  public static final String SIGN = "sign";
  // 加密算法
  public static final String ALGORITHM = "algorithm";

  public static void validate(HttpServletRequest request) {
    if (StringUtils.isEmpty(request.getParameter(COOPERATOR))) {
      throw new BizException(ChannelExceptionEnum.UN_RECOGNIZED_COOPERATOR);
    }

    if (StringUtils.isEmpty(request.getParameter(REQ_MSGID))) {
      throw new BizException(ChannelExceptionEnum.REQ_MSGID_CANNOT_EMPTY);
    }

    if (StringUtils.isEmpty(request.getParameter(SIGN))) {
      throw new BizException(ChannelExceptionEnum.SIGN_ERROR);
    }

    if (StringUtils.isEmpty(request.getParameter(ALGORITHM))) {
      throw new BizException(ChannelExceptionEnum.ALGORITHM_CANNOT_EMPTY);
    }
  }
}
